<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>江一行</title><meta name="author" content="江一行"><meta name="copyright" content="江一行"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="referrer" content="no-referrer"><meta name="description" content="个人博客">
<meta property="og:type" content="website">
<meta property="og:title" content="江一行">
<meta property="og:url" content="https://j_yh.gitee.io/index.html">
<meta property="og:site_name" content="江一行">
<meta property="og:description" content="个人博客">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://j_yh.gitee.io/img/avatar.png">
<meta property="article:author" content="江一行">
<meta property="article:tag" content="个人,blog,博客">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://j_yh.gitee.io/img/avatar.png"><link rel="shortcut icon" href="/img/favicon.ico"><link rel="canonical" href="https://j_yh.gitee.io/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '江一行',
  isPost: false,
  isHome: true,
  isHighlightShrink: true,
  isToc: false,
  postUpdate: '2023-03-04 13:17:10'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">5</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('/img/my/top.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="江一行"><span class="site-name">江一行</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">江一行</h1><div id="site-subtitle"><span id="subtitle"></span></div><div id="site_social_icons"><a class="social-icon" href="https://github.com/Jjiangyuhang" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="/jiang.yu.hang@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://space.bilibili.com/434232050" target="_blank" title="BiliBili"><i class="fa-brands fa-bilibili"></i></a></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/Java/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6/" title="类加载机制"><img class="post-bg" src="/img/my/archive.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="类加载机制"></a></div><div class="recent-post-info"><a class="article-title" href="/Java/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6/" title="类加载机制">类加载机制</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-03-04T02:35:24.000Z" title="发表于 2023-03-04 10:35:24">2023-03-04</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95/">面试</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/JVM/">JVM</a></span></div><div class="content">Java 代码的编译过程从 Javac 代码的总体结构来看，编译过程大致可以分为 1 个准备过程和 3 个处理过程。

准备过程：初始化插入式注解处理器。

解析与填充符号表过程，包括：

词法、语法分析，将源代码的字符流转变为标记集合，构造出抽象语法树。
填充符号表，产生符号地址和符号信息。


插入式注解处理器的注解处理过程：
在 Javac 源码中，插入式注解处理器的初始化过程是在 initPorcessAnnotations() 方法中完成的，而它的执行过程则是在 processAnnotations() 方法中完成。这个方法会判断是否还有新的注解处理器需要执行，如果有的话，通过 JavacProcessing-Environment 类的 doProcessing() 方法来生成一个新的JavaCompiler 对象，对编译的后续步骤进行处理。

分析与字节码生成过程，包括：

标注检查，对语法的静态信息进行检查。
数据流及控制流分析，对程序动态运行过程进行检查。
解语法糖，将简化代码编写的语法糖还原为原有的形式。
字节码生成，将前面各个步骤所生成的信息转化成字节码。



 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/Java/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" title="多线程"><img class="post-bg" src="/img/my/2510c39011c5be704182423e3a695e91.png" onerror="this.onerror=null;this.src='/img/404.png'" alt="多线程"></a></div><div class="recent-post-info"><a class="article-title" href="/Java/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" title="多线程">多线程</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-02-28T12:55:06.000Z" title="发表于 2023-02-28 20:55:06">2023-02-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95/">面试</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/">多线程</a></span></div><div class="content">线程的生命周期在线程的生命周期中，它要经过新建（New）、就绪（Ready）、运行（Running）、阻塞（Blocked）和死亡（Dead）5种状态。当线程启动后，它不能一直“霸占”着 CPU 独自运行，所以 CPU 需要在多条线程之间切换，于是线程状态也会多次在运行、就绪之间切换。

当使用 new 关键字创建了一个线程之后，该线程就处于新建状态，此时它和其他的Java对象一样，仅仅由 Java 虚拟机为其分配内存，并初始化其成员变量的值。此时的线程对象没有表现出任何线程的动态特征，程序也不会执行线程的线程执行体。
当线程对象调用了 start() 方法之后，该线程处于就绪状态，Java虚拟机会为其创建方法调用栈和程序计数器，处于这个状态中的线程并没有开始运行，只是表示该线程可以运行了。至于该线程何时开始运行，取决于 JVM 线程调度器的调度。
如果处于就绪状态的线程获得了 CPU，开始执行run()方法的线程执行体，则该线程处于运行状态，如果计算机只有一个 CPU，那么在任何时刻只有一个线程处于运行状态。当然，在一个多处理器的机器上，将会有多个线程并行执行；当线程数大于处理器数时 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/Java/%E9%9B%86%E5%90%88/" title="集合"><img class="post-bg" src="https://w.wallhaven.cc/full/lm/wallhaven-lmwg12.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="集合"></a></div><div class="recent-post-info"><a class="article-title" href="/Java/%E9%9B%86%E5%90%88/" title="集合">集合</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-02-27T16:22:33.000Z" title="发表于 2023-02-28 00:22:33">2023-02-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95/">面试</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E9%9B%86%E5%90%88/">集合</a></span></div><div class="content">概述Java 中的集合类主要由 Collection 和 Map 这两个接口派生而出，其中 Collection 接口又派生出三个子接口，分别是 Set、List、Queue。所有的 Java 集合类，都是 Set、List、Queue、Map 这四个接口的实现类，这四个接口将集合分成了四大类，其中

Set 代表无序的，元素不可重复的集合；
List 代表有序的，元素可以重复的集合；
Queue 代表先进先出（FIFO）的队列；
Map 代表具有映射关系（key-value）的集合。其所有的 key 是一个 Set 集合，即 key 无序且不能重复。

这些接口拥有众多的实现类，其中最常用的实现类有 HashSet、TreeSet、ArrayList、LinkedList、ArrayDeque、HashMap、TreeMap 等。
Collection体系：

Map体系：

紫色框体代表接口，其中加粗的是代表四类集合的接口。蓝色框体代表实现类，其中有阴影的是常用实现类。
Java 容器线程安全问题java.util 包下的集合类大部分都是线程不安全的，例如常用的 HashSet、T ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/Java/Java%E5%9F%BA%E7%A1%80/" title="Java 基础"><img class="post-bg" src="https://w.wallhaven.cc/full/4o/wallhaven-4oovr5.png" onerror="this.onerror=null;this.src='/img/404.png'" alt="Java 基础"></a></div><div class="recent-post-info"><a class="article-title" href="/Java/Java%E5%9F%BA%E7%A1%80/" title="Java 基础">Java 基础</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-02-27T13:30:00.000Z" title="发表于 2023-02-27 21:30:00">2023-02-27</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95/">面试</a></span></div><div class="content">前言网上整理的基础知识，没事的时候看看，加深概念。
Object 类
Class&lt;?&gt; getClass()：返回该对象的运行时类。
boolean equals(Object obj)：判断形参与该对象是否相等。
int hashCode()：返回该对象的 hashCode 值。默认情况下，该对象的地址。
String toString()：返回该对象的字符串表示，重写了 Object 类的 toString() 方法，用于返回可以表述该对象信息的字符串。

&#x3D;&#x3D; 和equals()&#x3D;&#x3D;运算符：

作用于基本数据类型时，比较两个数值是否相等；
作用于引用数据类型时，比较两个对象的内存地址是否相同，即判断它们是否为同一个对象；

equals()方法：

没有重写时，Object 默认以 == 来实现，即比较两个对象的内存地址是否相同；
进行重写后，一般会按照对象的内容来进行比较，若两个对象内容相同则认为对象相等，否则认为对象不等。

String 和 StringBuffer 和 StringBuilderString 类是不可变类 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/Java/%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6/" title="垃圾回收"><img class="post-bg" src="https://w.wallhaven.cc/full/n6/wallhaven-n6plgx.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="垃圾回收"></a></div><div class="recent-post-info"><a class="article-title" href="/Java/%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6/" title="垃圾回收">垃圾回收</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-02-25T03:02:39.000Z" title="发表于 2023-02-25 11:02:39">2023-02-25</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95/">面试</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/JVM/">JVM</a></span></div><div class="content">判断是否需要回收Java 中使用可达性分析算法
引用计数算法在对象中添加一个引用计数器，每有一个地方引用它时，引用计数器加一，引用失效时，引用计数器减一。
存在问题：引用计数很难解决对象之间相互循环引用，如 A 对象中有用到 B 对象，B 对象中用到 A 对象。
导致它们的引用计数不为零，引用计数算法也就不能回收它们。
可达性分析算法通过一系列称为 “GC Roots” 的根对象作为起始节点，从这些节点开始 ，根据引用关系向下搜索，搜索时走过的路径称为 “引用链”，如果一个对象到 GC Roots 之间没有引用链，则该对象是不能被再使用的。
固定作为 GC Roots 的对象:

虚拟机栈（栈帧中的本地变量表）中引用的对象，如被线程调用的方法堆栈中使用的参数、局部变量、临时变量。
方法区中静态属性引用的对象，如字符串常量池。
本地方法栈中的 JNI（Native 方法）引用的对象。
Java 虚拟机内部的引用，如基本数据类型 Class 对象；常驻异常对象（NPE、OOM）；系统类加载器等。
所有被同步锁（synchronized 关键字）持有的对象。
反映 Java 虚拟机内部情况的 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/Java/Java%E5%86%85%E5%AD%98%E5%8C%BA%E5%9F%9F/" title="Java运行时数据区"><img class="post-bg" src="https://w.wallhaven.cc/full/j8/wallhaven-j8x7ym.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="Java运行时数据区"></a></div><div class="recent-post-info"><a class="article-title" href="/Java/Java%E5%86%85%E5%AD%98%E5%8C%BA%E5%9F%9F/" title="Java运行时数据区">Java运行时数据区</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-02-24T16:17:12.000Z" title="发表于 2023-02-25 00:17:12">2023-02-25</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95/">面试</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/JVM/">JVM</a></span></div><div class="content">组成JVM 主要由四大部分组成：ClassLoader（类加载器），Runtime Data Area（运行时数据区），Execution Engine（执行引擎），Native Interface（本地库接口），下图可以大致描述 JVM 的结构。


ClassLoader：负责加载字节码文件即 class 文件，class 文件在文件开头有特定的文件标示，并且 ClassLoader 只负责class 文件的加载，至于它是否可以运行，则由 Execution Engine 决定。
Runtime Data Area：是存放数据的，分为五部分：Stack（虚拟机栈），Heap（堆），Method Area（方法区），PC Register（程序计数器），Native Method Stack（本地方法栈）。几乎所有的关于 Java 内存方面的问题，都是集中在这块。
Execution Engine：执行引擎，也叫 Interpreter。Class 文件被加载后，会把指令和数据信息放入内存中，Execution Engine 则负责把这些命令解释给操作系统，即将 JVM 指令集翻译为 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/%E6%95%B0%E6%8D%AE%E5%BA%93/redis%E5%9F%BA%E7%A1%80/" title="redis基础"><img class="post-bg" src="/img/my/363b122c528f54df4a0446b6bab05515.png" onerror="this.onerror=null;this.src='/img/404.png'" alt="redis基础"></a></div><div class="recent-post-info"><a class="article-title" href="/%E6%95%B0%E6%8D%AE%E5%BA%93/redis%E5%9F%BA%E7%A1%80/" title="redis基础">redis基础</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-02-23T12:59:47.000Z" title="发表于 2023-02-23 20:59:47">2023-02-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/redis/">redis</a></span></div><div class="content">Redis基础key-value键值对的方法存储数据，非关系型数据库
需要保证key的唯一性
数据结构String类型保存对象时，将其转为 json 字符串，作为 value 保存。会把一些不重要的数据存入：如 : “ “ { }等符号，占内存。
String类型是二进制安全的。可以包含任何数据。比如jpg图片或者序列化的对象 。
一个键最大能存储512MB
实例
redis 127.0.0.1:6379&gt; SET name &quot;张三&quot;OKredis 127.0.0.1:6379&gt; GET name&quot;张三&quot;

Hash类型特别适合存储对象
可以将对象中的每个字段独立存储。就是说可以把对的属性名和属性值 两者存入 value。可以针对字段做CRUD，占用内存少。
每个 hash 可以存储 232 - 1 键值对（40多亿）。
实例
redis 127.0.0.1:6379&gt; DEL personredis 127.0.0.1:6379&gt; HMSET person name &quot;zhangsan&quot; age &q ...</div></div></div><nav id="pagination"><div class="pagination"><span class="page-number current">1</span></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">江一行</div><div class="author-info__description">花有重开日，人无再少年</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">5</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/Jjiangyuhang"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/Jjiangyuhang" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="/jiang.yu.hang@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://space.bilibili.com/434232050" target="_blank" title="BiliBili"><i class="fa-brands fa-bilibili"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">一些学习笔记，欢迎交流讨论。</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/Java/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6/" title="类加载机制"><img src="/img/my/archive.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="类加载机制"/></a><div class="content"><a class="title" href="/Java/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6/" title="类加载机制">类加载机制</a><time datetime="2023-03-04T02:35:24.000Z" title="发表于 2023-03-04 10:35:24">2023-03-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/Java/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" title="多线程"><img src="/img/my/2510c39011c5be704182423e3a695e91.png" onerror="this.onerror=null;this.src='/img/404.png'" alt="多线程"/></a><div class="content"><a class="title" href="/Java/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" title="多线程">多线程</a><time datetime="2023-02-28T12:55:06.000Z" title="发表于 2023-02-28 20:55:06">2023-02-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/Java/%E9%9B%86%E5%90%88/" title="集合"><img src="https://w.wallhaven.cc/full/lm/wallhaven-lmwg12.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="集合"/></a><div class="content"><a class="title" href="/Java/%E9%9B%86%E5%90%88/" title="集合">集合</a><time datetime="2023-02-27T16:22:33.000Z" title="发表于 2023-02-28 00:22:33">2023-02-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/Java/Java%E5%9F%BA%E7%A1%80/" title="Java 基础"><img src="https://w.wallhaven.cc/full/4o/wallhaven-4oovr5.png" onerror="this.onerror=null;this.src='/img/404.png'" alt="Java 基础"/></a><div class="content"><a class="title" href="/Java/Java%E5%9F%BA%E7%A1%80/" title="Java 基础">Java 基础</a><time datetime="2023-02-27T13:30:00.000Z" title="发表于 2023-02-27 21:30:00">2023-02-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/Java/%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6/" title="垃圾回收"><img src="https://w.wallhaven.cc/full/n6/wallhaven-n6plgx.jpg" onerror="this.onerror=null;this.src='/img/404.png'" alt="垃圾回收"/></a><div class="content"><a class="title" href="/Java/%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6/" title="垃圾回收">垃圾回收</a><time datetime="2023-02-25T03:02:39.000Z" title="发表于 2023-02-25 11:02:39">2023-02-25</time></div></div></div></div><div class="card-widget" id="card-newest-comments"><div class="item-headline"><i class="fas fa-comment-dots"></i><span>最新评论</span></div><div class="aside-list"><span>正在加载中...</span></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Java/"><span class="card-category-list-name">Java</span><span class="card-category-list-count">6</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/"><span class="card-category-list-name">数据库</span><span class="card-category-list-count">1</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/redis/" style="font-size: 1.15em; color: rgb(110, 125, 197)">redis</a><a href="/tags/%E9%9D%A2%E8%AF%95/" style="font-size: 1.45em; color: rgb(17, 44, 124)">面试</a><a href="/tags/JVM/" style="font-size: 1.3em; color: rgb(172, 113, 154)">JVM</a><a href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 1.15em; color: rgb(146, 86, 165)">多线程</a><a href="/tags/%E9%9B%86%E5%90%88/" style="font-size: 1.15em; color: rgb(87, 14, 37)">集合</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/03/"><span class="card-archive-list-date">三月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/02/"><span class="card-archive-list-date">二月 2023</span><span class="card-archive-list-count">6</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">7</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2023-02-22T16:00:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">29k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2023-03-04T05:17:09.907Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 By 江一行</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>window.typedJSFn = {
  init: (str) => {
    window.typed = new Typed('#subtitle', Object.assign({
      strings: str,
      startDelay: 300,
      typeSpeed: 150,
      loop: true,
      backSpeed: 50,
    }, null))
  },
  run: (subtitleType) => {
    if (true) {
      if (typeof Typed === 'function') {
        subtitleType()
      } else {
        getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
      }
    } else {
      subtitleType()
    }
  }
}
</script><script>function subtitleType () {
  getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
    jinrishici.load(result =>{
      if (true) {
        const sub = []
        const content = result.data.content
        sub.unshift(content)
        typedJSFn.init(sub)
      } else {
        document.getElementById('subtitle').innerHTML = result.data.content
      }
    })
  })
}
typedJSFn.run(subtitleType)
</script></div><script src="https://cdn.jsdelivr.net/npm/blueimp-md5/js/md5.min.js"></script><script>window.addEventListener('load', () => {
  const changeContent = (content) => {
    if (content === '') return content

    content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
    content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
    content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
    content = content.replace(/<[^>]+>/g,"") // remove html tag

    if (content.length > 150) {
      content = content.substring(0,150) + '...'
    }
    return content
  }

  const getIcon = (icon, mail) => {
    if (icon) return icon
    let defaultIcon = '?d=monsterid'
    let iconUrl = `https://gravatar.loli.net/avatar/${md5(mail.toLowerCase()) + defaultIcon}`
    return iconUrl
  }

  const generateHtml = array => {
    let result = ''

    if (array.length) {
      for (let i = 0; i < array.length; i++) {
        result += '<div class=\'aside-list-item\'>'

        if (true) {
          const name = 'src'
          result += `<a href='${array[i].url}' class='thumbnail'><img ${name}='${array[i].avatar}' alt='${array[i].nick}'></a>`
        }

        result += `<div class='content'>
        <a class='comment' href='${array[i].url}' title='${array[i].content}'>${array[i].content}</a>
        <div class='name'><span>${array[i].nick} / </span><time datetime="${array[i].date}">${btf.diffDate(array[i].date, true)}</time></div>
        </div></div>`
      }
    } else {
      result += '没有评论'
    }

    let $dom = document.querySelector('#card-newest-comments .aside-list')
    $dom.innerHTML= result
    window.lazyLoadInstance && window.lazyLoadInstance.update()
    window.pjax && window.pjax.refresh($dom)
  }

  const getComment = () => {
    const serverURL = 'https://vnyeujKj.api.lncldglobal.com'

    var settings = {
      "method": "GET",
      "headers": {
        "X-LC-Id": 'vnyeujKjy6AaK5O0RLSaVwC9-gzGzoHsz',
        "X-LC-Key": 'P0RFxhK58YSXPxBnDRAbZgYd',
        "Content-Type": "application/json"
      },
    }

    fetch(`${serverURL}/1.1/classes/Comment?limit=6&order=-createdAt`,settings)
      .then(response => response.json())
      .then(data => {
        const valineArray = data.results.map(function (e) {
          return {
            'avatar': getIcon(e.QQAvatar, e.mail),
            'content': changeContent(e.comment),
            'nick': e.nick,
            'url': e.url + '#' + e.objectId,
            'date': e.updatedAt,
          }
        })
        saveToLocal.set('valine-newest-comments', JSON.stringify(valineArray), 10/(60*24))
        generateHtml(valineArray)
      }).catch(e => {
        const $dom = document.querySelector('#card-newest-comments .aside-list')
        $dom.innerHTML= "无法获取评论，请确认相关配置是否正确"
      }) 
  }

  const newestCommentInit = () => {
    if (document.querySelector('#card-newest-comments .aside-list')) {
      const data = saveToLocal.get('valine-newest-comments')
      if (data) {
        generateHtml(JSON.parse(data))
      } else {
        getComment()
      }
    }
  }

  newestCommentInit()
  document.addEventListener('pjax:complete', newestCommentInit)
})</script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>